#ifndef HISTREAMER_PLUGIN_INIF_PLUGIN_DEFINITION_H
#define HISTREAMER_PLUGIN_INIF_PLUGIN_DEFINITION_H

#include <string>
#include "common/plugin_types.h"

namespace OHOS {
namespace Multimedia {
namespace Plugin {

#define MAKE_VERSION(MAJOR,MINOR) ((((MAJOR) & 0xFFFF) <<16) | ((MINOR) & 0xFFFF))

#define PLUGIN_INTERFACE_VERSION_MAJOR (1)
#define PLUGIN_INTERFACE_VERSION_MINOR (0)
#define CODEC_API_VERSION MAKE_VERSION(PLUGIN_INTERFACE_VERSION_MAJOR, PLUGIN_INTERFACE_VERSION_MINOR)

enum struct LicenseType : uint8_t{
	APACHE_V2,
	LGPL,
};
	
struct PackageDef {
	uint32_t pkgVersion;
	std::string name;
	LicenseType licenseType;
};

template<typename T> 
using PluginCreatorFunc = std::shared_ptr<T>(*)(const std::string &name);


struct PluginDefBase       {
	uint32_t apiVersion;
	PluginType pluginType = pluginType::INVALID_TYPE;
	std::string name;
	std::string description;
	uint32_t rank;
};

struct Register{
	virtual Status AddPlugin(const PluginDefBase &def) = 0;
};

struct PackageRegister : Register{
	virtual Status AddPackage(const PackageDef &def) = 0;
};

using RegusterFunc =  Status (*)(std::shared_ptr<Register>reg    );
using UnregusterFunc = void (*)(    );

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
#define PLUGIN_EXPORT extern "C" __declspec(dllexport)
#else
#if defined(__GUNC__) || ( defined(__SUNPRO_C) && (__SUNPRO_C >=0x590) )
#define PLUGIN_EXPORT extern "C" __attribute__((visibility("default")))
#else
#define PLUGIN_EXPORT
#endif
#endif

#define PLUGIN_PASTE_ARGS(str1,str2) str1##str2

#define PLUGIN_PASTE(str1, str2) PLUGIN_PASTE_ARGS(str1,str2) 

#define PLUGIN_STRINGIFY_ARGS(str) #str

#define PLUGIN_STRINGIFY(str) PLUGIN_STRINGIFY_ARGS(str)

#define PLUGIN_DEFINITION(name, license, registerFunc, unregisterFunc)\
PLUGIN_EXPORT const OHOS::Multimedia::Plugin::Status\
PLUGIN_PASTE(register_, name)(std::shared_ptr<OHOS::Multimedia::Plugin::Register>reg) 
{\
	std::dynamic_pointer_cast<OHOS::Multimedia::Plugin::PackageRegister>(reg)-AddPackage(
		{PLUGIN_INTERFACE_VERSION, PLUGIN_STRINGIFY(name), license});
		return registerFunc(reg); \
}\

PLUGIN_EXPORT const void PLUGIN_PASTE(unregister, name)(){unregisterFunc();}


}//naspace plugin
}//multi
} //ohos
#endif





	
